/*
 * @lc app=leetcode.cn id=53 lang=cpp
 *
 * [53] 最大子序和
 */

// @lc code=start
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int pre = nums[0];
        int  max=pre;
        for(int i = 1; i < nums.size() ;i++){
            if( nums[i] >= pre + nums[i] )
                pre=nums[i];
            else pre=pre + nums[i];
            max=max>pre?max:pre;

        }

        return max;
        
    }
};
// @lc code=end

